package com.komeri.komeriapl;

import java.util.List;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 2014/10/10
 * adapter of barcode info history
 * @author Ma MengHong
 *
 */
public class HistoryAdapter extends BaseAdapter{
	
	public Context context;
	private List<BarCodeInfo> infoList;
	public final String Tag ="HistoryAdapter";
	public HistoryAdapter adapter;
	
	
	
	public HistoryAdapter(Context ct,List<BarCodeInfo> list){
		this.context = ct;
		this.infoList = list;
		
		adapter = this;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return infoList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return infoList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder viewHolder = null;
		  
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.adapter_history, null);
            viewHolder.time = (TextView) convertView.findViewById(R.id.adapter_history_time); 
            viewHolder.content = (TextView) convertView.findViewById(R.id.adapter_history_content); 
            
            convertView.setTag(viewHolder);
        } else {
        	
            viewHolder = (ViewHolder) convertView.getTag();
        }
        
       
        viewHolder.time.setText(infoList.get(position).add_time);
        if(infoList.get(position).title!=null){
        	viewHolder.content.setText(infoList.get(position).title);
        }else{
        	viewHolder.content.setText(infoList.get(position).content);
        }
        
        

        
		return convertView;
	}
	public final static class ViewHolder {
        TextView time;
        TextView content;
        
        
    }
	

	
	
	

}